
# include <bits/stdc++.h>
# define mid ((l + r) >> 1)
# define MAXN 100023
using namespace std;
inline int gn() { 
    int k = 0, f = 1;
    char c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
    return k * f;
}

int cnt;

struct temp { 
    int fr, to;
    temp() {;}
    temp(int fr_, int to_) {fr = fr_, to = to_;}
}num[MAXN];

struct edge { 
    int to, w;
    edge *ne;
    inline edge() { 
        to = w = 0;
        ne = NULL;
    }
    inline edge(int to_, int w_, edge *ne_) { 
        to = to_, w = w_, ne = ne_;
    } 
}*head[MAXN];

inline void addedge(int fr, int to, int w) { 
    num[++cnt] = temp(fr, to);
    head[fr] = new edge(to, w, head[fr]);
    head[to] = new edge(fr, w, head[to]);
}

int n;

int a[MAXN], fa[MAXN], siz[MAXN], son[MAXN], dep[MAXN], q[MAXN], l, r;

inline void bfs() { 
    l = r = 1;
    q[1] = 1; 
    dep[1] = 1;
    while(l <= r) { 
        int u = q[l++];
        siz[u] = 1;
        for(edge *e = head[u]; e; e = e->ne) { 
            if(e->to == fa[u]) continue;
            a[e->to] = e->w;
            fa[e->to] = u;
            dep[e->to] = dep[u] + 1;
            q[++r] = e->to;
        }
    }
    for(int i = r; i; i--) { 
        siz[fa[q[i]]] += siz[q[i]];
        if(siz[son[fa[q[i]]]] < siz[q[i]]) son[fa[q[i]]] = q[i];
    }
}

int top[MAXN], dfn[MAXN], adfn[MAXN] ,id;

void dfs(int u, int tp) { 
    dfn[++id] = u;
    adfn[u] = id;
    top[u] = tp;
    if(!son[u]) return;
    else dfs(son[u], tp);
    for(edge *e = head[u]; e; e = e->ne) { 
        if(top[e->to]) continue;
        dfs(e->to, e->to);
    }
}

int mx[MAXN << 2], M;

inline void build() { 
    for(M = 1; M <= n + 1; M <<= 1);
    for(int i = 1; i <= n; i++) { 
        mx[i + M] = adfn[i];
    }
    for(int i = M; i; i--) { 
        mx[i] = max(mx[i << 1], mx[i << 1 | 1]);
    }
}

inline void change_zkw(int x, int p) { 
    x += M;
    mx[x] = p;
    for(x >>= 1; x; x >>= 1) { 
        mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
    }
}

inline int query_zkw(int l, int r) { 
   int ans = 0;
   for(l += M - 1, r += M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) { 
       if(~l & 1) ans = max(ans, mx[l + 1]);
       if(r & 1) ans = max(ans, mx[r - 1]);
   }
   return ans;
}

inline int query(int u, int v) { 
# define tu top[u]
# define tv top[v]
    int ans = 0;
    while(tu != tv) { 
        if(dep[tu] < dep[tv]) swap(u, v);
        ans = max(ans, query(adfn[tu], adfn[u]));
        u = fa[tu];
    }
    if(dep[u] > dep[v]) swap(u, v);
    ans = max(ans, query_zkw(adfn[u] + 1, adfn[v]));
    return ans;
}

char op[10];

int main() { 
# ifndef LOCAL
    freopen("qtree.in", "r", stdin);
    freopen("qtree.out", "w", stdout);
# else 
    freopen("in", "r", stdin);
# endif
    n = gn();
    for(int i = 1; i < n; i++) { 
        int a = gn(), b = gn(), c = gn();
        addedge(a, b, c);
    }
    bfs();
    dfs(1, 1);
    build();
    while(true) { 
        scanf("%s", op);
        if(op[0] == 'D') break;
        switch(op[0]) { 
            case 'Q':{ 
                int u = gn(), v = gn();
                printf("%d\n", query(u, v));
                break;
            }
            case 'C':{ 
                int x = gn(), p = gn();
                int qaq = num[x].fr;
                int quq = num[x].to;
                qaq = (dep[qaq] > dep[quq]) ? qaq : quq;
                change_zkw(adfn[qaq], p);
                break;
            }
        }
    }
}
